define(['knockout', 'eventbus'], function (ko, eventbus) {
	return function () {
		// List of portal items for the frontpage
		let portalItems = ko.observable([]);

		// Populates the list with predefined portal items.
		let fillPortalItems = function(){
			portalItems(
				[
					{ heading: "Search & History", componentName: "search-and-history", iconPath: "/img/search.svg" },
					{ heading: "Saved questions", componentName : "saved-questions", iconPath: "/img/saved.svg" },
					{ heading: "List questions", componentName : "list-questions", iconPath: "/img/list.svg" },
					{ heading: "Word clouds", componentName : "word-clouds", iconPath: "/img/cloud.svg" },
				]
			);
		};

		// Click callback for the portal items.
		let changeComponent = function(portalItem) {
			eventbus.publish("changeComponentEvent", portalItem.componentName);
		}

		// Initialize the page with portal items.
		fillPortalItems();

		// Expose the proprieties needed in the UI.
		return {
			title: 'Home page',
			portalItems,
			changeComponent,
		}
	}
});